﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AutoTLBB
{
	public partial class SkillDefineControl : UserControl
	{
		private SkillDefine m_dataContext;
		private bool IsBinding = false;
		private int m_column1Width = 20;
		public SkillDefineControl()
		{
			InitializeComponent();

			m_chkIsSelected.CheckedChanged += new EventHandler(CheckedChanged);
			m_txtDelay.TextChanged += new EventHandler(DelayChanged);
			m_cbxSkill.SelectedIndexChanged += new EventHandler(SkillChanged);
			m_cbxSkill.DataSource = Enum.GetValues(typeof(UserKey));
		}
		void SkillChanged(object sender, EventArgs e)
		{
			if (m_dataContext == null || IsBinding) { return; }
			m_dataContext.SkillKey = (UserKey)m_cbxSkill.SelectedItem;
		}
		void DelayChanged(object sender, EventArgs e)
		{
			if (m_dataContext == null || IsBinding) { return; }
			m_dataContext.Value =string.IsNullOrEmpty(m_txtDelay.Text)? 0: Int32.Parse(m_txtDelay.Text);
		}
		void CheckedChanged(object sender, EventArgs e)
		{
			if (m_dataContext == null || IsBinding) { return; }
			m_dataContext.IsSelected = m_chkIsSelected.Checked;
		}
		public void SetDataContext(SkillDefine skillDefine)
		{
			m_dataContext = skillDefine;
			IsBinding = true;
			m_chkIsSelected.Checked = m_dataContext.IsSelected;
			m_chkIsSelected.Text = m_dataContext.SkillName;
			m_txtDelay.Text = m_dataContext.Value.ToString();
			m_cbxSkill.SelectedItem = m_dataContext.SkillKey;
			
			IsBinding = false;
		}
		[Description("Test text displayed in the textbox"), Category("Data")] 
		public bool DelayVisbile
		{
			set
			{
				m_txtDelay.Visible = value;
			}
			get
			{
				return m_txtDelay.Visible;
			}
		}
		[Description("Test text displayed in the textbox"), Category("Data")]
		public string Label
		{
			set
			{
				label1.Text = value;
			}
			get
			{
				return label1.Text;
			}
		}
		[Description("Test text displayed in the textbox"), Category("Data")]
		public int MinColumn1Width{
			set
			{
				if (value > 20 && tableLayoutPanel1.ColumnStyles.Count>0)
				{
					tableLayoutPanel1.ColumnStyles[0].SizeType = SizeType.Absolute;
					tableLayoutPanel1.ColumnStyles[0].Width = value;
					m_column1Width = value;
				}
			}
			get{
				return m_column1Width;
			}
		}
		[Description("Hide Delay box"), Category("Data")]
		public bool HideDelay
		{
			get
			{
				return m_txtDelay.Visible;
			}
			set
			{
				m_txtDelay.Visible = value;
			}
		}
	}
}
